<!DOCTYPE html>
<html>
<head>
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">

    <meta charset="UTF-8">
    <title>已办</title>
    <link rel="stylesheet" type="text/css" media="screen" href="../../css/bootstrap.min.css">
    <link rel="stylesheet" type="text/css" media="screen" href="../../css/dataTables.bootstrap.min.css">
    <link rel="stylesheet" type="text/css" media="screen" href="../../layui/css/layui.css">
    <link rel="stylesheet" href="../../css/global.css" media="all"/>
</head>
<body>
<div class="col-xs-12 col-sm-12 col-md-12 col-lg-12 page-container">
    <header class="form-filter-wrap">
        <form class="layui-form form-inline" onsubmit="return false">
            <div class="form-group">
                <div class="form-filter">
                    <div class="form-inner">
                        <label class="layui-form-label">单位：</label>
                        <div class="layui-input-inline">
                            <select multiple lay-omit id="branch" lay-search>
                                <option value="">请选择</option>
                            </select>
                        </div>
                    </div>
                    <div class="form-inner">
                        <label class="layui-form-label">巡察年度：</label>
                        <div class="layui-input-inline">

                            <select multiple lay-omit id="startPatrolTime">
                                <option value="">请选择</option>
                            </select>
                        </div>
                    </div>
                    <div class="form-inner">
                        <label class="layui-form-label">问题类别：</label>
                        <div class="layui-input-inline">
                            <select multiple lay-omit id="questionType">
                                <option value="">请选择</option>
                            </select>
                        </div>
                    </div>
                    <button id="searchBt" class="layui-btn layui-btn-sm"><i class="layui-icon">&#xe615;</i>搜索
                    </button>
                </div>
                <div class="form-btn">
                    <button type="button" class="layui-btn layui-btn-sm" id="test4"><i class="layui-icon"></i>查看附件列表
                    </button>
                </div>
            </div>

        </form>
    </header>

    <div class="content-container">
        <div class="widget-body no-padding">
            <table id="dt-table" class="table table-striped table-bordered table-hover" style="width: 100%">
                <thead>
                <tr>
                    <th></th>
                    <th >单位</th>
                    <th >巡察年度</th>
                    <th>问题项</th>
                    <th >问题分类</th>
                    <!--<th>录入时间</th>-->
                    <th >督察人员</th>

                    <th></th>
                </tr>
                </thead>
                <tbody>
                </tbody>
            </table>
        </div>
    </div>
</div>
<!--附件下载-->
<div id="hidden1" lay-filter="hidden1" style="display: none">
    <table id="department_result" lay-filter="department_result"></table>
</div>
<div id="openProductBox2" style="display: none; padding: 10px;">
    <button type="button" lay-event="del" class="layui-btn layui-btn-sm" id="down"><i class="layui-icon"></i>查看附件详情</button>
    <table class="layui-hide" id="test" lay-filter="test"></table>
</div>

<!--删除按钮-->
<script type="text/html" id="itemTpl">
    {{# if( d.type == 2 && d.delated == 0){ }}
    <button type="button" lay-event="del1" class="layui-btn layui-btn-sm" id="del1"><i class="layui-icon"></i>删除
    </button>
    {{# } }}

    {{# if( d.type == 3 && d.delated == 1){ }}
    <button type="button" lay-event="del2" class="layui-btn layui-btn-sm" id="del2"><i class="layui-icon"></i>删除
    </button>
    {{# } }}
</script>

<script type="text/javascript" src="../../js/libs/jquery-1.11.1.min.js"></script>
<script type="text/javascript" src="../../js/jq.js"></script>
<script type="text/javascript" src="../../js/plugin/datatables/jquery.dataTables.min.js"></script>
<script type="text/javascript" src="../../js/plugin/datatables/dataTables.bootstrap.min.js"></script>
<script type="text/javascript" src="../../js/my/permission.js"></script>
<script type="text/javascript" src="../../layui/layui.js"></script>
<script type="text/javascript" src="../../js/dict.js"></script>
<script type="text/javascript" src="../../js/plugin/jquery-download.js"></script>
<script type="text/javascript">
    layui.use('layer', function () {
        var layer = layui.layer;
    });
    /*公司*/
    layui.use(['layer', 'form', 'jquery'], function () {
        var form = layui.form;
        $.ajax({
            url: '/dropDown/getBranch',
            dataType: 'json',
            type: 'post',
            success: function (data) {
                // 使用循环遍历，给下拉列表赋值
                $.each(data, function (index, value) {
                    $('#branch').append(new Option(value.value, value.key));// 下拉菜单里添加元素
                });
                form.render();//重新渲染 固定写法
            }
        })
            /*年度*/
            , $.ajax({
            url: '/dropDown/getYear',
            dataType: 'json',
            type: 'post',
            success: function (data) {
                // 使用循环遍历，给下拉列表赋值
                $.each(data, function (index, value) {
                    $('#startPatrolTime').append(new Option(value.value, value.value));// 下拉菜单里添加元素
                });
                form.render();//重新渲染 固定写法
            }
        })
            ,
            /*问题类别*/
            $.ajax({
                url: '/dropDown/getQuestion',
                dataType: 'json',
                type: 'post',
                success: function (data) {
                    // 使用循环遍历，给下拉列表赋值
                    $.each(data, function (index, value) {
                        $('#questionType').append(new Option(value.value, value.value));// 下拉菜单里添加元素
                    });
                    form.render();//重新渲染 固定写法
                }
            })


    });


    var pers = checkPermission();

    var example;

    function init() {
        example =
            $('#dt-table').DataTable({
                retrieve: true,
                "searching": false,
                "processing": false,
                "serverSide": true,
                "ordering": false,
                "language": {
                    "url": "/js/plugin/datatables/Chinese.lang"
                },
                "ajax": {
                    "url": "/mOverseeQuestions/yibanList",
                    "type": "get",
                    "data": function (d) {
                        if ($("#questionType").val() != null) {
                            d.questionType = JSON.stringify($("#questionType").val());
                        }
                        if ($("#startPatrolTime").val() != null) {
                            d.startPatrolTime = JSON.stringify($("#startPatrolTime").val());
                        }
                        if ($("#branch").val() != null) {
                            d.branchId = JSON.stringify($("#branch").val());
                        }
                    },
                    "error": function (xhr, textStatus, errorThrown) {
                        var msg = xhr.responseText;
                        console.log(msg);
                        var response = JSON.parse(msg);
                        var code = response.code;
                        var message = response.message;
                        if (code == 400) {
                            layer.msg(message);
                        } else if (code == 401) {
                            localStorage.removeItem("token");
                            layer.msg("token过期，请先登录", {shift: -1, time: 1000}, function () {
                                location.href = '/login.html';
                            });
                        } else if (code == 403) {
                            console.log("未授权:" + message);
                            layer.msg('未授权');
                        } else if (code == 500) {
                            layer.msg('系统错误：' + message);
                        }
                    }
                },
                "autoWidth": true,
                "dom": "<'dt-toolbar'r>t<'dt-toolbar-footer'<'table-bottom col-sm-10 col-xs-12 hidden-xs'i><'table-bottom col-xs-12 col-sm-10' p v>>",
                "columns": [
                    {
                        "data": "id",
                        "render": function (data, type, row, meta) {
                            return "<input type='radio' class='table-checkbox'  name='childclick' id='' value=" + data + " />";
                        }
                    },
                    {"width":"150","data": "branch", "defaultContent": ""},
                    {"width":"100","data": "startPatrolTime", "defaultContent": ""},
                    {
                        "data": "question", "defaultContent": "",
                        render: function (data, type, row, meta) {
                            if (data) {
                                if (data.length > 50) {
                                    return '<div style="text-align: left">'+data.substr(0, 50) + " <a style='color: #1E9FFF ;font-size: 8px' href='javascript:void(0);' onclick='javascript:searchBtn3(\"" + data + "\", \"" + '问题项' + "\")' ><i style='font-weight: bold' class='layui-icon layui-icon-search'></i></a>" +'</div>';
                                } else {
                                    return '<div style="text-align: left">'+data+'</div>';
                                }
                            } else {
                                return "";
                            }
                        }
                    },
                    {"width":"250","data": "questionType", "defaultContent": ""},
                    {"width":"150","data": "oversee", "defaultContent": ""},


                    {
                        "data": "",
                        "defaultContent": "",
                        "orderable": false,
                        "render": function (data, type, row) {
                            var id = row['id'];
                            var href = "yibanQuestionPanel.html?id=" + id;
                            var edit = buttonOpen(href, "", pers);
                            return edit;
                        }
                    },

                ],
                "order": [[0, "asc"]]
            });

        return example
    }

    // 失败审核
    function rev(id) {
        layui.use('layer', function () { //独立版的layer无需执行这一句
            var $ = layui.jquery, layer = layui.layer; //独立版的layer无需执行这一句
            var remarkReason = "";
            layer.prompt({
                formType: 0,
                value: '',
                title: '请输入不通过原因',
                btn: ['确定', '取消'], //按钮，
                btnAlign: 'c'
            }, function (value) {
                remarkReason = value;
                var status = '失败';
                var param = {
                    id: id,
                    remark: value,
                    status: status
                };
                var s = JSON.stringify(param);
                console.log(s);

                //执行不通过
                /*var ids = "";
                for (var i = 0; i < data.length; i++) {
                    ids += data[i].id + ",";
                }*/
                $.ajax({
                    type: 'POST',
                    contentType: "application/json; charset=utf-8",
                    url: "/review/reviewQuestion",
                    data: s,
                    dataType: "json",
                    success: function (data) {
                        if (data.success) {
                            layer.closeAll();
                            example.ajax.reload();
                        }
                        console.log(data);

                    }
                });
            });
        })
    }


    function searchBtn3(id, title) {
        layer.open({
            type: 1
            , title: '<div class="layui-icon" style="font-weight: bold; text-align: center">' + title + '</div>'
            , area: ["600px", ""]
            , content: '<div style="padding: 20px;font-size:18px;line-height:30px;">' + id + '</div>'
            , btnAlign: 'c' //按钮居中
            , shade: 0.3 //不显示遮罩
            , shadeClose: false
            , yes: function () {
                layer.closeAll();
            }
        });

    }

    // 通过审核
    function revs(id) {
        layui.use('layer', function () { //独立版的layer无需执行这一句
            var $ = layui.jquery, layer = layui.layer; //独立版的layer无需执行这一句
            var remarkReason = "";
            layer.prompt({
                formType: 0,
                value: '',
                title: '备注',
                btn: ['确定', '取消'], //按钮，
                btnAlign: 'c'
            }, function (value) {
                remarkReason = value;
                var status = '成功';
                var param = {
                    id: id,
                    remark: value,
                    status: status
                };
                var s = JSON.stringify(param);
                console.log(s);

                //执行不通过
                /*var ids = "";
                for (var i = 0; i < data.length; i++) {
                    ids += data[i].id + ",";
                }*/
                $.ajax({
                    type: 'POST',
                    contentType: "application/json; charset=utf-8",
                    url: "/review/reviewQuestion",
                    data: s,
                    dataType: "json",
                    success: function (res) {
                        console.log(res);

                        if (res.errorCode == 0) {
                            layer.closeAll();
                            example.ajax.reload();
                        } else {
                            layer.closeAll();
                            layer.msg(res.errorMsg);
                        }


                    }
                });
            });
        })
    }

    // 发起修改
    function edit(data) {
        //window.open(data, 'newwindow','menubar=0,scrollbar=0,resizable=1,channelmode=1,location=0,status=1')
        // window.open(data, 'newwindow', 'width=' + (window.screen.availWidth - 10) + ',height=' + (window.screen.availHeight - 70) + ',top=0,left=0,menubar=0,scrollbar=0,resizable=1,channelmode=1,location=0,status=1')
        window.open(data)
    }

    //下面为点击首项选中子项;子项全选,首项选中
    $('#checkAll').on('click', function () {
        if (this.checked) {
            $(this).attr('checked', 'checked')
            $("input[name='childclick']").each(function () {
                this.checked = true;
            });
        } else {
            $(this).removeAttr('checked')
            $("input[name='childclick']").each(function () {
                this.checked = false;
            });
        }
    });

    function childclick() {

        if ($(this).is(":checked") == false) {
            $("#checkAll").prop("checked", false);
        }
        if ($("input[name='childclick']:checked").length == $("input[name='childclick']").length) {
            $("#checkAll").prop("checked", true);

        }
    }

    $("#test4").click(function () {

        layui.use(['table', 'form'], function () {

            var table = layui.table;


            var id = $('input[type="radio"]:checked').val()

            console.log($('input[type="radio"]:checked').val())

            var form = layui.form;

            if (id.length > 0) {

                $.ajax({
                    url: '/mOverseeQuestions/fileList',
                    dataType: 'json',
                    type: 'post',
                    data: {id: id},
                    success: function (data) {
                        if (data.count === 0) {
                            layer.msg('未上传附件');
                        } else {
                            layer.open({
                                type: 1,
                                title: '<div class="layui-icon" style="font-weight: bold;text-align: center"> 附件列表</div>',
                                area: ['80%', '80%'], //宽高
                                content: $('#openProductBox2'),
                                success: function (data) {

                                    table.render({
                                        elem: '#test',
                                        width: '100%'
                                        , method: 'post', //接口http请求类型，默认：get
                                        page: false,
                                        limit: Number.MAX_VALUE,
                                        url: '/mOverseeQuestions/fileList', //?page=1&limit=10（该参数可通过 request 自定义）
                                        where: {id: id},
                                        cols: [[
                                            {
                                                type: 'checkbox'
                                            }, {
                                                field: 'branch', //字段名
                                                title: '单位名称', //标题
                                                width: 200
                                                //fixed: 'left' //固定列
                                            }, {
                                                field: 'question', //字段名
                                                title: '问题项', //标题
                                                width: 260
                                            }, {
                                                field: 'path', //字段名
                                                title: '附件名称', //标题
                                                width: 454
                                            }, {
                                                field: '', title: '操作',
                                                width: 80,
                                                toolbar: '#itemTpl',
                                                fixed: 'right' //固定列
                                            }]
                                        ],
                                        done: function (res, curr, count) {
                                            $('th').css({'font-weight': 'bold'});
                                        }
                                    });
                                }
                            });
                        }
                    }
                })

            }
        });
        layui.use('table', function () {
            var table = layui.table;

            //监听行工具事件
            table.on('tool(test)', function (obj) {
                var checkStatus = layui.table.checkStatus('openProductBox2').data;
                var data = obj.data;
                //console.log(data)
                if (obj.event === 'del') {
                    var s = data.path;
                    location.href = '/mOverseeQuestions/downSource?path=' + s;
                }
                if (obj.event === 'del1') {
                    var id = data.id;
                    $.ajax({
                        url: '/mOverseeQuestions/deletePathOne?id=' + id,
                        type: 'get',
                        success: function () {
                            layer.msg("删除申请已发出", {
                                icon: 1,
                                time: 1000
                            });
                            table.reload("test");
                        }
                    })
                }
                if (obj.event === 'del2') {
                    var id = data.id;
                    $.ajax({
                        url: '/mOverseeQuestions/deletePathTwo?id=' + id,
                        type: 'get',
                        success: function () {
                            layer.msg("删除成功", {
                                icon: 1,
                                time: 1000
                            });
                            table.reload("test");
                        }
                    })
                }
            });
        });

        // 附件下载
        function sleep(n) {
            var start = new Date().getTime();//定义起bai始时间的毫秒数
            while (true) {
                var time = new Date().getTime();//每次执行循环取得du一次当前时间的毫秒数
                if (time - start > n) {//如果当前时间的毫秒数减去起始时间的毫秒数大于给定的毫秒数，即结束循环
                    break;
                }
            }
        }

        function aa() {
            var checkStatus = layui.table.checkStatus('test').data;
            var ids = [];
            for (var i = 0; i < checkStatus.length; i++) {
                ids.push(checkStatus[i].id)
            }
            if (ids.length === 0) {
                layer.msg('请选择数据查看');
                return
            }


            var url = "/mOverseeQuestions/downSource?id=" + encodeURI(JSON.stringify(ids));
            $.fileDownload(url, {
                httpMethod: 'GET',
                //同时上传表单数据
                data: '',
                prepareCallback: function (url) {
                    $('#down').attr('disabled', false)
                    console.log("请稍等！");
                },
                successCallback: function (url) {

                    $('#down').attr('disabled', false)
                    return false
                },
                failCallback: function (html, url) {
                    var json = JSON.parse(html);
                    console.log(json);
                    $('#down').attr('disabled', false)
                }
            });
            return false
        }
        $('#down').on('click',  function () {
            aa()
        })
    })


    $("#searchBt").click(function () {
        init().ajax.reload();
    });

    init()
</script>
</body>
</html>

